                                if ($_POST["submit"] == "Excel") {

                                    function getExcelData($data) {
                                        $retval = "";
                                        if (is_array($data) && !empty($data)) {
                                            $row = 0;
                                            foreach (array_values($data) as $_data) {
                                                if (is_array($_data) && !empty($_data)) {
                                                    if ($row == 0) {
                                                        // write the column headers
                                                        $retval = implode(",", array_keys($_data));
                                                        $retval .= "\n";
                                                    }
                                                    //create a line of values for this row...
                                                    $retval .= implode(",", array_values($_data));
                                                    $retval .= "\n";
                                                    //increment the row so we don't create headers all over again
                                                    $row++;
                                                }
                                            }
                                        }
                                        return $retval;
                                    }

                                    $get2 = mysql_query("SELECT `a`.`hajino`, `a`.`paxid`, `a`.`surname`, `a`.`name`, `a`.`midname`, `a`.`suffix`, `b`.`dept_date`, `b`.`airline_code`, `b`.`flightno`, `b`.`ticketno`, `b`.`pnr`, `b`.`sramt` FROM `pax` a, `airline_detail` b WHERE `a`.`paxid` = `b`.`paxno` and `b`.`srno` = 2 and  `a`.`name` IS NOT NULL $ncond2 $pcond2 $dcond2 $scond2 $fcond2 $surcond2 $compcond2 $bcond3 $acond2 $adcond2 $pnrcond2 $tktcond2 $tqcond2 ORDER BY $sortby2 ") or die(mysql_error());
                                    while ($row = mysql_fetch_assoc($get2)) {
                                        $aData[] = $row;
                                    }

                                    $contents = getExcelData($aData);
                                    $filename = "Airticket" . '.csv'; //"myExcelFile.xls";
                                    header("Content-type: application/octet-stream");
                                    header("Content-Disposition: attachment; filename=" . $filename);

                                    $expiredate = time() + 30;
                                    $expireheader = "Expires: " . gmdate("D, d M Y G:i:s", $expiredate) . " GMT";
                                    header($expireheader);
                                    echo $contents;
                                    exit;
